/**
 * 
 */
package com.williamoneil.charts.client.data;

import com.google.gwt.canvas.dom.client.Context2d;

/**
 * @author gudipati
 *
 */
public class ChartBoundsRect {

	private int absoluteLeft = 0;
	private int absoluteTop = 0;
	private int x = 10;
	private int y = 10;
	private int totalHeight = 0;
	private int totalWidth = 0;
	
	public ChartBoundsRect(int absLeft, int absTop, int height, int width) {
		super();
		this.absoluteLeft = absLeft;
		this.absoluteTop = absTop;
		this.totalHeight = height;
		this.totalWidth = width;
	}
	/**
	 * @return the x
	 */
	public int getX() {
		return x;
	}
	/**
	 * @return the y
	 */
	public int getY() {
		return y;
	}
	/**
	 * @return the totalHeight
	 */
	public int getTotalHeight() {
		return totalHeight;
	}
	/**
	 * @return the totalWidth
	 */
	public int getTotalWidth() {
		return totalWidth;
	}
	/**
	 * @return the absoluteLeft
	 */
	public int getAbsoluteLeft() {
		return absoluteLeft;
	}
	/**
	 * @return the absoluteTop
	 */
	public int getAbsoluteTop() {
		return absoluteTop;
	}
	public int getXScaleLabelWidth() {
		return 50;
	}
	
	public int getYScaleLabelHeight() {
		return 15;
	}
	
	public int getWidthWithScale() {
		return totalWidth - (2*x);
	}
	
	public int getHeightWithScale() {
		return totalHeight - (2*x);
	}
	
	public int getWidthWithoutScale() {
		return getWidthWithScale() - getXScaleLabelWidth();
	}
	
	public int getHeightWithoutScale() {
		return getHeightWithScale() - getYScaleLabelHeight();
	}

	public boolean isXWithinBounds(final int pointX) {
		return (pointX > x && pointX <= getWidthWithoutScale());
	}

	public boolean isYWithinBounds(final int pointY) {
		return (pointY >= y && pointY <= getHeightWithoutScale());
	}

	public boolean isWithinBounds(final int pointX, final int pointY) {
		return isXWithinBounds(pointX) && isYWithinBounds(pointY);
	}
	
	public boolean isWithinYScale(final int pointX, final int pointY) {
		return isYWithinBounds(pointY) && (pointX >= getWidthWithoutScale() && pointX <= getTotalWidth()); 
	}
	
	@Deprecated
	public void drawChartBounds(final Context2d context) {
		context.rect(x, y, totalWidth, totalHeight);
	}
	
	@Override
	public String toString() {
		return "x=" + x + ";y=" + y + ";th=" + totalHeight + ";tw=" + totalWidth;
	}
}
